package com.antipov.odp.rmi.server;

import com.antipov.odp.rmi.intf.PointService;
import com.antipov.odp.rmi.valueobjects.Point;

import java.rmi.RemoteException;

/**
 * Created with IntelliJ IDEA.
 * User: Andrew Antipov
 * Date: 19.02.14
 * Time: 1:47
 */
public class PointServiceBean implements PointService {

	@Override
	public Double distance(Point a, Point b) throws RemoteException{
		double dx = a.getX() - b.getX();
		double dy = a.getY() - b.getY();
		return Math.sqrt(dx * dx + dy * dy);
	}

	@Override
	public Double lengthRadius(Point a, Point b) throws RemoteException{
		return 2 * Math.PI * distance(a, b);
	}

	@Override
	public Double lengthDiameter(Point a, Point b) throws RemoteException{
		return Math.PI * distance(a, b);
	}

	@Override
	public Double squareRadius(Point a, Point b) throws RemoteException{
		double r = distance(a, b);
		return Math.PI * r * r;
	}

	@Override
	public Double squareDiameter(Point a, Point b) throws RemoteException{
		double d = distance(a, b);
		return Math.PI * d * d / 4.0;
	}
}
